from selenium import webdriver
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select

# driver = webdriver.Chrome("C:/Users/EDZ/AppData/Local/Google/Chrome/Application/chromedriver.exe")

# 声明浏览器
browser = webdriver.Chrome()

# 找到html文件并打开
Path_name = 'D:/Python学习-100天/Day51/selenium.html'

browser.get(Path_name)

# 将浏览器最大化
time.sleep(2)
browser.maximize_window()

# 查找元素并操作
time.sleep(2)
User_name = browser.find_element_by_css_selector('div#signup input[name="username"]').send_keys('rabbit')
time.sleep(2)
Pass_word = browser.find_element_by_css_selector('div#signup input[name="password"]').send_keys('love')

# 下拉选择 深圳
time.sleep(2)
selector=Select(browser.find_element_by_name("city"))
selector.select_by_index("3")
# selector.select_by_value("sz")

# 提交表单
time.sleep(2)
# submit = browser.find_element_by_css_selector('div#signup form').submit()
# submit = browser.find_element_by_xpath("//input[@type='submit']").submit()
submit =browser.find_element_by_xpath("//input[@type='submit']").click()
# time.sleep(10)


# 显示等待
result = WebDriverWait(browser, 10, 1).until(
    lambda x: x.find_element_by_css_selector("div#signup p").text == "注册成功")


# 关闭浏览器
browser.quit()
